package com.qf.controller;

import com.qf.feign.AddressFeign;
import com.qf.pojo.User;
import com.qf.pojo.UserAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author wbzs,
 * @date 2022/10/19,
 * @time 23:00,
 */
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private AddressFeign addressFeign;
    @RequestMapping("info/{id}")
    public User findByid( @PathVariable Integer id){
        System.out.println("我进来啦");

        User user = new User();
        user.setId(id);
        user.setName("张飞");
        //需要地址信息，地址需要找地址的程序获取
        /**
         * 参数一：我们的请求地址
         * 参数二：我们期望网络请求返回的数据解析为什么类型
         * 参数三：有没有key=value格式的参数
         *
         */
        UserAddress addressByid = addressFeign.findAddressByid(id);
        user.setUserAddress(addressByid);
        return user;

    }
    @RequestMapping("/infos/{id}")
    public User get(@PathVariable Integer id){
        User user= new User();
        user.setId(id);
        user.setName("上海");
        UserAddress userAddress = addressFeign.findByid(id, "山东");
        user.setUserAddress(userAddress);
        return user;

    }


    @RequestMapping("/address")
    public User getuser( UserAddress userAddress){
        System.out.println("userAddress:"+userAddress);
        UserAddress byAddress = addressFeign.findByAddress(userAddress);
        User user = new User();
        user.setUserAddress(byAddress);
        return user;

    }


}
